<?php

namespace app\common\model;

use think\Model;

class CommunitySellerRelation extends Model
{
    
    /**
     * 根据seller_id获取商家的所有社区
     */
    public function get_relation_by_seller_id($seller_id)
    {
        $data = $this
            ->where('seller_id',$seller_id)->paginate(30,false,['query'=>request()->param()]);
        return $data;
    }

    /**
     * 批量加入商家的社区
     * @param $seller_id
     * @param $categories
     */
    public function addListSellerCommunityRelation($seller_id,$categories)
    {
        foreach ($categories as $item) {
            $relation = new self();
            $relation->seller_id = $seller_id;
            $relation->community_id = $item;
            $relation->save();
        }
    }

    /**
     * 批量删除某个商家的全部社区
     * @param $seller_id
     */
    public function delSellerCommunityRelation($seller_id)
    {
        $relation = new self();
        $data = $relation->where('seller_id',$seller_id);
        $data->delete();
    }
}
